package com.ruoyi.activity.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.ruoyi.activity.domian.RedPacketRecord;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.type.JdbcType;

public interface RedPacketRecordDao extends BaseMapper<RedPacketRecord> {
    /**
     * 获取某用户发红包历史总和
     * @author chengjian
     * @date 2021/8/13 10:50 上午
     * @param uid 用户uid
     * @return Long 单位：分
     */
    @Select({
            "select sum(money) as totalMoney from red_packet_record where uid = #{uid}"
    })
    @Result(column = "totalMoney", property = "totalMoney", jdbcType = JdbcType.BIGINT)
    Long getSumMoneyByUid(@Param("uid") String uid);

    /**
     * 获取某用户在某段时间发红包历史总和
     * @author chengjian
     * @date 2021/8/13 10:50 上午
     * @param uid 用户uid
     * @param start 开始时间
     * @param end 结束时间
     * @return Long 单位：分
     */
    @Select({
            "select sum(money) as totalMoney from red_packet_record where uid = #{uid} and create_time >= #{start} and create_time <= #{end} "
    })
    @Result(column = "totalMoney", property = "totalMoney", jdbcType = JdbcType.BIGINT)
    Long getSumMoneyByUidAndTime(@Param("uid") String uid,
                                 @Param("start") String start,
                                 @Param("end") String end);
}
